<template>
  <div class="home">
    <HomeHeader ></HomeHeader>
    <HomeSwiper :List = "swiper"></HomeSwiper>
    <HomeIcon :list="icon"></HomeIcon>
    <HomeRecomend :List ="Recomend"></HomeRecomend>
    <HomeWeekend :List = "weekend"></HomeWeekend>
  </div>
</template>

<script>
// @ is an alias to /src
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcon from './components/icon'
import HomeRecomend from './components/Recommend'
import HomeWeekend from './components/Weekend'
import axios from 'axios'
export default {
  name: 'home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeRecomend,
    HomeWeekend,
    HomeIcon
  },
  methods: {
    getHomeInfo () {
      axios.get('/api/index.json?city=' + this.city)
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {

        let data = res.data // 接收到的数据
        console.log(data.data)
      if (data.ret && data.data) {  // 检验数据是否存在   返回值是否正确
        let datas = data.data;
        this.swiper = datas.swiperList;
        this.icon = datas.iconList;
        this.Recomend = datas.recommendList;
        this.weekend = datas.weekendList;
      }
    }
  },
  activated (){

      if( this.city == "" || this.city !== this.$store.state.city){

        this.city = this.$store.state.city;
         this.getHomeInfo();
      }


  },
  data (){
    return {
      swiper:[],
      icon:[],
     Recomend:[],
     weekend:[],
     city:""
    }
  }
}
</script>

<style >
</style>
